import { ChatClient } from 'dify-client'
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { API_KEY, API_URL } from '@/config'

export const client = new ChatClient(API_KEY, API_URL.replace('/v1', '') || undefined)
export async function POST(request: NextRequest, { params }: {
  params: { conversationId: string }
}) {
  const body = await request.json()
  const {
    name,
  } = body
  const { conversationId } = params
  // 调整为本地生成，直接使用第一条消息为标题
  const { data }: any = await client.sendRequest('POST', `/api/chat-messages/${conversationId}/stop`, body)
  console.log('OPS:', { conversationId, name, data })
  return NextResponse.json(data)
}
